package com.wjl.shop.service.impl;

import com.wjl.shop.entity.Enclosure;
import com.wjl.shop.dao.EnclosureDao;
import com.wjl.shop.service.EnclosureService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 附件表(Enclosure)表服务实现类
 *
 * @author makejava
 * @since 2021-10-06 14:43:20
 */
@Service("enclosureService")
public class EnclosureServiceImpl implements EnclosureService {
    @Resource
    private EnclosureDao enclosureDao;

    @Override
    public Map<String, Object> selectFile(String orderCode) {
        HashMap<String, Object> map = new HashMap<>();
        List<Map<String, Object>> list = enclosureDao.selectFile(orderCode);
        map.put("code", 1);
        map.put("message", "查询成功！");
        map.put("data",list);
        return map;
    }

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Enclosure queryById(Integer id) {
        return this.enclosureDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<Enclosure> queryAllByLimit(int offset, int limit) {
        return this.enclosureDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param enclosure 实例对象
     * @return 实例对象
     */
    @Override
    public Enclosure insert(Enclosure enclosure) {
        this.enclosureDao.insert(enclosure);
        return enclosure;
    }

    /**
     * 修改数据
     *
     * @param enclosure 实例对象
     * @return 实例对象
     */
    @Override
    public Enclosure update(Enclosure enclosure) {
        this.enclosureDao.update(enclosure);
        return this.queryById(enclosure.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.enclosureDao.deleteById(id) > 0;
    }
}
